home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / t-bcinfo.zip / TI713.ZIP / TI713.ASC
Text File  |  1992-02-25  |  5KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  713
  9.   VERSION  :  2.0
  10.        OS  :  DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/3
  12.  
  13.     TITLE  : Switching a Device Driver Between Cooked and Raw Mode
  14.  
  15.  
  16.  
  17.  
  18.   /**************************************************************************
  19.       FUNCTION:  setdevmode
  20.  
  21.           PURPOSE:
  22.                   This function will swap a device driver
  23.                   associated with the given stream into either a
  24.                   raw (binary) or a cooked (ASCII) mode. This is
  25.                   useful for outputting to the screen or printer in
  26.                   a binary mode.  Note that once this bit is set
  27.                   all output to the device is received from the
  28.                   device driver in the mode indicated by bit 5.
  29.                   This is true even if you do not use a binary read
  30.                   or write command.
  31.  
  32.           METHOD:
  33.                   This function will call, via the ioctl()
  34.                   function,  int 21h / function 44h / subfunction 0
  35.                   to get the current device status word.  The high
  36.                   order byte of the word is then cleared and then
  37.                   bit 5 is set to the selected mode. The ioctl() is
  38.                   then again called this time using subfunction 1
  39.                   to set a new status.
  40.  
  41.           PARAMETERS:
  42.                   This function takes two arguments, both are type
  43.                   integer.  The first is the number of the handle
  44.                   associated with the targeted device driver.  The
  45.                   second is the mode the device driver is to be put
  46.                   into:
  47.  
  48.                           1 = raw (binary) mode
  49.                           2 = cooked (ASCII) mode
  50.  
  51.                   All other values for parameters are invalid and
  52.                   will generate an error.
  53.  
  54.           RETURN VALUE:
  55.                   This function will return a 0 on error, 1 if
  56.                   the new mode is raw and 2 if the new mode is
  57.                   cooked.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                            NUMBER  :  713
  75.   VERSION  :  2.0
  76.        OS  :  DOS
  77.      DATE  :  February 25, 1992                        PAGE  :  2/3
  78.  
  79.     TITLE  :  Switching a Device Driver Between Cooked and Raw Mode
  80.  
  81.  
  82.  
  83.  
  84.           IMPLEMENTATION:
  85.                   This function can be implemented by including the
  86.                   prototype:  " int setdevmode( int, int); " within
  87.                   file scope of your calling program.  Within file
  88.                   scope implies external to all functions. You
  89.                   would then need to compile this file and link it
  90.                   into the executable. Once this is done you can
  91.                   simply make function calls to setdevmode() like
  92.                   any other function.
  93.  
  94.   ***********************************************************************/
  95.  
  96.   #include <io.h>
  97.  
  98.   int setdevmode(int handle, int mode)
  99.   {
  100.      int ret,                   /* Function return value         */
  101.          word,                  /* Device driver status          */
  102.          mask =  0x0020,        /* Mask to set bit 5             */
  103.          mask2 = 0x00ff,        /* Mask to clear high order bits */
  104.          mask3 = 0x00df;        /* Mask to clear bit 5           */
  105.  
  106.     if( mode < 1 || mode >2 )   /* Check for a valid mode        */
  107.             return (0);
  108.  
  109.     word = ioctl( handle, 0, 0, 0 ); /* Get current driver status*/
  110.     if( word == -1 )            /* Check for an error            */
  111.        return (0);
  112.  
  113.     word &= mask2;              /* Clear high order bits         */
  114.     if( word & mask )           /* Check if bit 5 is set (raw)   */
  115.     {
  116.        if( mode == 2 )          /* Check if ASCII is requested   */
  117.          word &= mask3;         /* Clear bit 5 setting cooked    */
  118.     }
  119.     else
  120.        if( mode == 1 )          /* Check if binary is requested  */
  121.          word |= mask;          /* Set bit 5 setting raw         */
  122.  
  123.     ret = ioctl( handle, 1, word, 0); /* Change the device driver
  124.                                          status */
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                            NUMBER  :  713
  141.   VERSION  :  2.0
  142.        OS  :  DOS
  143.      DATE  :  February 25, 1992                        PAGE  :  3/3
  144.  
  145.     TITLE  :  Switching a Device Driver Between Cooked and Raw Mode
  146.  
  147.  
  148.  
  149.  
  150.     if( ret == -1 )             /* Check for an error            */
  151.        return (0);
  152.     else
  153.        return (mode);           /* Return new device driver mode */
  154.   }
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.